package com.nettest.dao.system;

import org.apache.log4j.Logger;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Service;

import com.nettest.entity.system.Role;
import com.nettest.service.BaseServiceForHibernate;
@Service
public class RoleDao extends BaseServiceForHibernate<Role>{
	static Logger logger = Logger.getLogger(RoleDao.class
			.getName());

	public String queryMaxRoleId(String parentId) {
		String sql = "SELECT max(role_id) roleId" +
				"           FROM t_role" +
				"          where parent_id = :parentId";
		SQLQuery query = super.getSession().createSQLQuery(sql);
		Object result = query.setString("parentId", parentId).uniqueResult();
		if(result != null) {
			return String.valueOf(result);
		}
		return null;
	}

	public void delRoleById(String roleId) {
		String sql = "DELETE FROM t_role r WHERE r.role_id LIKE :roleId";
		super.getSession().createSQLQuery(sql).setString("roleId", roleId + "%").executeUpdate();
	}
}
